import java.util.Scanner;

public class Main {





    //非对称之美
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        String aa = in.nextLine();
        char[] a = aa.toCharArray();
        int left = 0;
        int right = a.length-1;
        while(left<right && a[left] == a[right]){
            left++;
            right--;
        }
        int ret = 0;
        for(int i = 1;i<a.length;i++){
            if(a[i] != a[i-1]){
                ret = 1;
            }
        }
        if(ret == 0){
            System.out.print(0);
        }else if(left>=right){
            System.out.println(a.length-1);
        }else{
            System.out.println(a.length);
        }
    }










    //连续子数组最大和
    public static int FindGreatestSumOfSubArray(int[] array){
        int max = array[0];
        int len = array.length;
        int[] dp = new int[len+1];
        for (int i = 1; i < len+1; i++) {
            if(dp[i-1]>0){
                dp[i] = dp[i-1] +array[i-1];
            }else{
                dp[i] = array[i-1];
            }
            if(dp[i] >max){
                max = dp[i];
            }
        }
        return max;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = in.nextInt();
        }
        int max = FindGreatestSumOfSubArray(array);
        System.out.println(max);

    }













    //经此一役小红所向无敌
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        long a = 0L;
        long h = 0L;
        long b = 0L;
        long k = 0L;
        long damage = 0L;
        long[] arr = new long[4];
        for (int i = 0; i < 4; i++) {
            arr[i] = in.nextLong();
        }
        a = arr[0];
        h = arr[1];
        b = arr[2];
        k = arr[3];

        long num1 = k/a;
        long num2 = h/b;

        if(k%a != 0){
            num1++;
        }
        if(h%b != 0){
            num2++;
        }

        long count = Math.min(num1,num2);
        damage += count*(a+b);
        if(num1 != num2){
            damage += num1>num2 ? b*10 : a*10;
        }
        System.out.println(damage);
    }










}
